package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.RbacManagerDao;
import com.woniuxy.entity.PageEntity;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ideaAdmin
 * TODO:
 * Date: 2022/2/21:13:10
 * Description:
 */
@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    @Autowired
    RbacManagerDao rbacManagerDao;


    @Override
    public ResponseEntity<PageInfo> findAll(PageEntity pageSize) {

        PageHelper.startPage(pageSize.getPage(),pageSize.getLimit());

        ResponseEntity<PageInfo> listResponseEntity = new ResponseEntity<>();

        List<RbacManager> rbacManagers =rbacManagerDao.findAll(pageSize);

        PageInfo<RbacManager> of = PageInfo.of(rbacManagers);
        if(rbacManagers.size() >  0){
            listResponseEntity.setCode(200);
            listResponseEntity.setMsg("查询成功");
            listResponseEntity.setData(of);
        }else {
            listResponseEntity.setCode(500);
            listResponseEntity.setMsg("查询失败");
            listResponseEntity.setData(null);
        }

        return listResponseEntity;
    }

    @Override
    public ResponseEntity delOne(Integer id) {
        ResponseEntity listResponseEntity = new ResponseEntity();
        if(rbacManagerDao.delById(id)>0){
            listResponseEntity.setCode(200);
            listResponseEntity.setMsg("删除用户成功");
        }else {
            listResponseEntity.setCode(500);
            listResponseEntity.setMsg("系统维护者");
        }
        return listResponseEntity;
    }

    @Override
    public ResponseEntity addOne(RbacManager rbacManager) {
        ResponseEntity listResponseEntity = new ResponseEntity();
        if(rbacManagerDao.addOne(rbacManager)>0){
            listResponseEntity.setCode(200);
            listResponseEntity.setMsg("删除用户成功");
        }else {
            listResponseEntity.setCode(500);
            listResponseEntity.setMsg("系统维护者");
        }
        return listResponseEntity;
    }

    @Override
    public ResponseEntity updateOne(RbacManager rbacManager) {
        ResponseEntity listResponseEntity = new ResponseEntity();

        if(rbacManagerDao.updateById(rbacManager)>0){
            listResponseEntity.setCode(200);
            listResponseEntity.setMsg("删除用户成功");
        }else {
            listResponseEntity.setCode(500);
            listResponseEntity.setMsg("系统维护中");
        }
        return listResponseEntity;
    }
}
